home *** CD-ROM | disk | FTP | other *** search
- /** DoRev Header ** Do not edit! **
- *
- * Name : fMoire.c
- * Copyright : Free Software
- * Creation date : 12-May-93
- * Translator : SAS/C 6.2
- * Compiler opts. : See Makefile
- *
- * Date Rev Author Comment
- * --------- --- ------------------- ----------------------------------------
- * 12-May-93 0 Michael D. Bayne Bouncing lines blanker module
- *
- *** DoRev End **/
-
- #include <exec/types.h>
- #include <exec/memory.h>
-
- #include <intuition/intuition.h>
- #include <intuition/screens.h>
-
- #include <libraries/gadtools.h>
- #include <dos/dos.h>
- #include <graphics/gfxbase.h>
- #include <graphics/gfxmacros.h>
- #include <graphics/copper.h>
- #include <graphics/videocontrol.h>
- #include <hardware/custom.h>
-
- #include <clib/exec_protos.h>
- #include <clib/intuition_protos.h>
- #include <clib/graphics_protos.h>
- #include <clib/alib_protos.h>
- #include <clib/gadtools_protos.h>
- #include <clib/utility_protos.h>
-
- #include <stdlib.h>
-
- #include "Moire.h"
- #include "/defs.h"
-
- extern struct Custom far custom;
-
- struct mPrefObject {
- LONG xSpeed, ySpeed, Trail, Cycle;
- };
-
- #pragma libcall GfxBase LoadRGB32 372 9802
-
- extern int RangeRand( int );
-
- struct mPrefObject nP;
- STATIC const UBYTE VersTag[] = "\0$VER:Moire 1.1 (5.12.93)";
- UBYTE infoString[] = "Moire (Bouncing lines) Module";
-
- void setMoirePrefs( void )
- {
- GT_SetGadgetAttrs( MoireGadgets[GD_TRAIL], MoireWnd, 0L, GTSL_Level, nP.Trail, 0L );
- GT_SetGadgetAttrs( MoireGadgets[GD_XSPEED], MoireWnd, 0L, GTSL_Level, nP.xSpeed, 0L );
- GT_SetGadgetAttrs( MoireGadgets[GD_YSPEED], MoireWnd, 0L, GTSL_Level, nP.ySpeed, 0L );
- GT_SetGadgetAttrs( MoireGadgets[GD_CYCLE], MoireWnd, 0L, GTCY_Active, nP.Cycle, 0L );
- }
-
- int OKClicked( void )
- {
- return( QUIT );
- }
-
- int CANCELClicked( void )
- {
- return( CANCEL );
- }
-
- int TRAILClicked( void )
- {
- nP.Trail = MoireMsg.Code;
- return( OK );
- }
-
- int CYCLEClicked( void )
- {
- nP.Cycle = MoireMsg.Code;
- return( OK );
- }
-
- int XSPEEDClicked( void )
- {
- nP.xSpeed = MoireMsg.Code;
- return( OK );
- }
-
- int YSPEEDClicked( void )
- {
- nP.ySpeed = MoireMsg.Code;
- return( OK );
- }
-
- int MoireVanillaKey( void )
- {
- switch( MoireMsg.Code ) {
- case 'o':
- return( QUIT );
- case 'c':
- return( QUIT );
- case 't':
- GT_SetGadgetAttrs( MoireGadgets[GD_TRAIL], MoireWnd, 0L, GTSL_Level, ++(nP.Trail) > 256 ?
- nP.Trail = 256 : nP.Trail, 0L );
- return( OK );
- case 'T':
- GT_SetGadgetAttrs( MoireGadgets[GD_TRAIL], MoireWnd, 0L, GTSL_Level, --(nP.Trail) < 1 ?
- nP.Trail = 1 : nP.Trail , 0L );
- return( OK );
- case 'x':
- GT_SetGadgetAttrs( MoireGadgets[GD_XSPEED], MoireWnd, 0L, GTSL_Level, ++(nP.xSpeed) > 64 ?
- nP.xSpeed = 64 : nP.xSpeed, 0L );
- return( OK );
- case 'X':
- GT_SetGadgetAttrs( MoireGadgets[GD_XSPEED], MoireWnd, 0L, GTSL_Level, --(nP.xSpeed) < 1 ?
- nP.xSpeed = 1 : nP.xSpeed, 0L );
- return( OK );
- case 'y':
- GT_SetGadgetAttrs( MoireGadgets[GD_YSPEED], MoireWnd, 0L, GTSL_Level, ++(nP.ySpeed) > 64 ?
- nP.ySpeed = 64 : nP.ySpeed, 0L );
- return( OK );
- case 'Y':
- GT_SetGadgetAttrs( MoireGadgets[GD_YSPEED], MoireWnd, 0L, GTSL_Level, --(nP.ySpeed) < 1 ?
- nP.ySpeed = 1 : nP.ySpeed, 0L );
- return( OK );
- default:
- return( OK );
- }
- }
-
- void defaults( UBYTE *prefData )
- {
- (( struct mPrefObject * )prefData)->xSpeed = 16;
- (( struct mPrefObject * )prefData)->ySpeed = 16;
- (( struct mPrefObject * )prefData)->Trail = 64;
- (( struct mPrefObject * )prefData)->Cycle = 0;
- }
-
- void prefs( UBYTE *prefData )
- {
- LONG retval = OK;
-
- CopyMem( prefData, &nP, sizeof( struct mPrefObject ));
- if( !SetupScreen() ) { if( !OpenMoireWindow()) {
- CloseDownScreen();
- setMoirePrefs();
- while( 1 ) {
- WaitPort( MoireWnd->UserPort );
- retval = HandleMoireIDCMP();
- if( retval == QUIT ) {
- CopyMem( &nP, prefData, sizeof( struct mPrefObject ));
- break;
- }
- if( retval == CANCEL ) break;
- }
- CloseMoireWindow();
- } } else CloseDownScreen();
- }
-
- void agaInit( struct Screen *Screen, LONG numCols )
- {
- ULONG *agaTable, i, tPos;
-
- agaTable = AllocMem(( numCols*3 + 2 )*sizeof( ULONG ), MEMF_CLEAR );
-
- agaTable[0] = ( numCols<<16 );
- agaTable[1] = agaTable[2] = agaTable[3] = 0;
- tPos = 3;
- for( i = 1; i < numCols/3+1; ++i ) {
- agaTable[++tPos] = (0xFFFFFF)|((numCols-3*i)<<24);
- agaTable[++tPos] = (0xFFFFFF)|((3*i)<<24);
- agaTable[++tPos] = (0xFFFFFF);
- }
- for( i = 1; i < numCols/3+1; ++i ) {
- agaTable[++tPos] = (0xFFFFFF);
- agaTable[++tPos] = (0xFFFFFF)|((numCols-3*i)<<24);
- agaTable[++tPos] = (0xFFFFFF)|((3*i)<<24);
- }
- for( i = 1; i < numCols/3+1; ++i ) {
- agaTable[++tPos] = (0xFFFFFF)|((3*i)<<24);
- agaTable[++tPos] = (0xFFFFFF);
- agaTable[++tPos] = (0xFFFFFF)|((numCols-3*i)<<24);
- }
- agaTable[++tPos] = 0;
-
- LoadRGB32( &(Screen->ViewPort), agaTable );
- }
-
- void ecsInit( struct Screen *Screen, LONG numCols )
- {
- UWORD Table6[] = { 0, 0x0F20, 0x0E30, 0x0C50, 0x0B60, 0x0980, 0x0890, 0x06B0,
- 0x05C0, 0x03E0, 0x02F0, 0x00F2, 0x00E3, 0x00C5, 0x00B6, 0x0098, 0x006B,
- 0x005C, 0x003E, 0x002F, 0x020F, 0x030E, 0x050C, 0x060B, 0x0809, 0x0908,
- 0x0B06, 0x0C05, 0x0E03, 0x0F02, 0x0F00, 0x0F00, 0x0F20, 0x0E30, 0x0C50,
- 0x0B60, 0x0980, 0x0890, 0x06B0, 0x05C0, 0x03E0, 0x02F0, 0x00F2, 0x00E3,
- 0x00C5, 0x00B6, 0x0098, 0x006B, 0x005C, 0x003E, 0x002F, 0x020F, 0x030E,
- 0x050C, 0x060B, 0x0809, 0x0908, 0x0B06, 0x0C05, 0x0E03, 0x0F02, 0x0F00 };
- UWORD Table5[] = { 0, 0x0F20, 0x0E30, 0x0C50, 0x0B60, 0x0980, 0x0890, 0x06B0,
- 0x05C0, 0x03E0, 0x02F0, 0x00F2, 0x00E3, 0x00C5, 0x00B6, 0x0098, 0x006B,
- 0x005C, 0x003E, 0x002F, 0x020F, 0x030E, 0x050C, 0x060B, 0x0809, 0x0908,
- 0x0B06, 0x0C05, 0x0E03, 0x0F02, 0x0F00 };
- UWORD Table4[] = { 0, 0x0E03, 0x0B06, 0x0909, 0x060B, 0x030E, 0x003E, 0x006B,
- 0x0099, 0x00B6, 0x00E3, 0x03E0, 0x06B0, 0x0990, 0x0B60, 0x0E30 };
- UWORD Table3[] = { 0, 0x0E00, 0x0770, 0x00E0, 0x0077, 0x000E, 0x0707 };
- UWORD Table2[] = { 0, 0x0E00, 0x00E0, 0x000E };
- UWORD Table1[] = { 0, 0x0FFF };
- UWORD *Table[6];
-
- Table[0] = Table1; Table[1] = Table2; Table[2] = Table3; Table[3] = Table4;
- Table[4] = Table5, Table[5] = Table6;
-
- LoadRGB4( &(Screen->ViewPort), Table[Screen->BitMap.Depth-1], numCols );
- }
-
- VOID newCopperList( LONG height, struct ViewPort *vp )
- {
- #define NUMCOLORS 45
-
- struct UCopList *uCopList;
- struct TagItem uCopTags[] = { { VTAG_USERCLIP_SET, 0L }, { VTAG_END_CM, 0L } };
- register USHORT i, index = rand()%NUMCOLORS, spc;
- UWORD spectrum[] = { 0x0F00, 0x0E10, 0x0D20, 0x0C30, 0x0B40, 0x0A50, 0x0960, 0x0870, 0x0780, 0x0690,
- 0x05A0, 0x04B0, 0x03C0, 0x02D0, 0x01E0, 0x00F0, 0x00E1, 0x00D2, 0x00C3, 0x00B4,
- 0x00A5, 0x0096, 0x0087, 0x0078, 0x0069, 0x005A, 0x004B, 0x003C, 0x002D, 0x001E,
- 0x000F, 0x010E, 0x020D, 0x030C, 0x040B, 0x050A, 0x0609, 0x0708, 0x0807, 0x0906,
- 0x0A05, 0x0B04, 0x0C03, 0x0D02, 0x0E01 };
-
- if( uCopList = ( struct UCopList * )AllocMem( sizeof( struct UCopList ), MEMF_PUBLIC|MEMF_CLEAR )) {
-
- spc = height/NUMCOLORS;
-
- CINIT( uCopList, NUMCOLORS );
-
- for( i = 0; i<NUMCOLORS; ++i ) {
- CWAIT( uCopList, i*spc, 0 );
- CMOVE( uCopList, custom.color[1], spectrum[(i+index)%NUMCOLORS] );
- }
-
- CEND( uCopList );
-
- Forbid();
- vp->UCopIns = uCopList;
- Permit();
-
- VideoControl( vp->ColorMap, uCopTags );
-
- RethinkDisplay();
- }
- }
-
- void blank( struct bMessage *Msg )
- {
- struct mPrefObject *nP = ( struct mPrefObject * )Msg->prefData;
- struct Screen *MoireScr;
- struct RastPort *rp;
-
- ULONG numCols, i, j, n, Trail = nP->Trail, xSpeed = nP->xSpeed, ySpeed = nP->ySpeed;
- WORD Wid, Hei, *cx1, *cy1, *cx2, *cy2, dx1, dy1, dx2, dy2;
-
- srand( VBeamPos());
-
- MoireScr = OpenScreenTags( 0l, SA_DisplayID, Msg->sMod, SA_Depth, Msg->sDep, SA_Quiet, TRUE,
- SA_Overscan, OSCAN_STANDARD, TAG_DONE );
-
- rp = &( MoireScr->RastPort );
- Wid = MoireScr->Width;
- Hei = MoireScr->Height;
-
- numCols = (( 1 << MoireScr->BitMap.Depth )-1)%3 ? ( 1 << MoireScr->BitMap.Depth )-1 :
- ( 1 << MoireScr->BitMap.Depth );
-
- if( numCols == 1 ) numCols = 2;
-
- cx1 = AllocMem( Trail*sizeof( UWORD ), MEMF_CLEAR );
- cy1 = AllocMem( Trail*sizeof( UWORD ), MEMF_CLEAR );
- cx2 = AllocMem( Trail*sizeof( UWORD ), MEMF_CLEAR );
- cy2 = AllocMem( Trail*sizeof( UWORD ), MEMF_CLEAR );
-
- SetRGB4( &(MoireScr->ViewPort), 0, 0, 0, 0 );
-
- switch( nP->Cycle ) {
- case 0:
- if( MoireScr->BitMap.Depth > 6 ) agaInit( MoireScr, numCols );
- else ecsInit( MoireScr, numCols );
- break;
- case 1:
- SetRGB4( &(MoireScr->ViewPort), 1, rand()%15 + 1, rand()%15 + 1, rand()%15 + 1 );
- break;
- case 2:
- SetRGB4( &(MoireScr->ViewPort), 1, 15, 15, 15 );
- break;
- case 3:
- newCopperList( Hei, &( MoireScr->ViewPort ));
- break;
- }
-
- cx1[1] = RangeRand( Wid )+1; cy1[1] = RangeRand( Hei )+1;
- cx2[1] = RangeRand( Wid )+1; cy2[1] = RangeRand( Hei )+1;
- dx1 = RangeRand( xSpeed )+1; dy1 = RangeRand( ySpeed )+1;
- dx2 = RangeRand( xSpeed )+1; dy2 = RangeRand( ySpeed )+1;
- i = 0; j = 0;
-
- while(!(SetSignal(0,0) & SIGBREAKF_CTRL_C )) {
- i = (i+1) % Trail;
- n = (i+1) % Trail;
- j = (j+1) % 255;
-
- if( !nP->Cycle ) SetAPen( rp, (j*(numCols-1))/255+1 );
- else SetAPen( rp, 1 );
-
- if( cx1[i] >= Wid ) {
- dx1 = -1*RangeRand( xSpeed )-1;
- cx1[i] = Wid-1;
- } else if( cx1[i] < 0 ) {
- dx1 = RangeRand( xSpeed )+1;
- cx1[i] = 0;
- }
- if( cx2[i] >= Wid ) {
- dx2 = -1*RangeRand( xSpeed )-1;
- cx2[i] = Wid-1;
- } else if( cx2[i] < 0 ) {
- dx2 = RangeRand( xSpeed )+1;
- cx2[i] = 0;
- }
- if( cy1[i] >= Hei ) {
- dy1 = -1*RangeRand( ySpeed )-1;
- cy1[i] = Hei-1;
- } else if( cy1[i] < 0 ) {
- dy1 = RangeRand( ySpeed )+1;
- cy1[i] = 0;
- }
- if( cy2[i] >= Hei ) {
- dy2 = -1*RangeRand( ySpeed )-1;
- cy2[i] = Hei-1;
- } else if( cy2[i] < 0 ) {
- dy2 = RangeRand( ySpeed )+1;
- cy2[i] = 0;
- }
-
- Move( rp, cx1[i], cy1[i] );
- Draw( rp, cx2[i], cy2[i] );
-
- SetAPen( rp, 0 );
- Move( rp, cx1[n], cy1[n] );
- Draw( rp, cx2[n], cy2[n] );
-
- cx1[n] = cx1[i] + dx1;
- cy1[n] = cy1[i] + dy1;
- cx2[n] = cx2[i] + dx2;
- cy2[n] = cy2[i] + dy2;
- }
-
- SetSignal( 0L, SIGBREAKF_CTRL_C );
-
- FreeMem( cx1, Trail*sizeof( UWORD ) );
- FreeMem( cx2, Trail*sizeof( UWORD ) );
- FreeMem( cy1, Trail*sizeof( UWORD ) );
- FreeMem( cy2, Trail*sizeof( UWORD ) );
-
- CloseScreen( MoireScr );
- }
-